package com.yida.gwj.deposit.service.impl;

import com.yida.common.core.utils.DateUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.deposit.domain.GwjDepositBusinessHouse;
import com.yida.gwj.deposit.domain.dto.refund.GwjRefundCompleteHouseDetailDTO;
import com.yida.gwj.deposit.domain.dto.split.GwjFundsSplitBusinessHouseDTO;
import com.yida.gwj.deposit.domain.request.split.GwjFundsSplitBusinessHouseRequest;
import com.yida.gwj.deposit.mapper.GwjDepositBusinessHouseMapper;
import com.yida.gwj.deposit.service.IGwjDepositBusinessHouseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * 业务房屋信息（缴存业务管理模块）Service业务层处理
 *
 * @author lqq
 * @date 2023-01-10
 */
@Service
public class GwjDepositBusinessHouseServiceImpl implements IGwjDepositBusinessHouseService {

	@Resource
	private GwjDepositBusinessHouseMapper gwjDepositBusinessHouseMapper;

	/**
	 * 查询业务房屋信息（缴存业务管理模块）
	 *
	 * @param bizHouseId 业务房屋信息（缴存业务管理模块）主键
	 * @return 业务房屋信息（缴存业务管理模块）
	 */
	@Override
	public GwjDepositBusinessHouse selectGwjDepositBusinessHouseByBizHouseId(Long bizHouseId) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseByBizHouseId(bizHouseId);
	}

	/**
	 * 查询业务房屋信息（缴存业务管理模块）
	 *
	 * @param houseId 房屋ID
	 * @param bizId   业务ID
	 * @return 业务房屋信息（缴存业务管理模块）
	 */
	@Override
	public GwjDepositBusinessHouse selectGwjDepositBusinessHouseByHouseIdAndBizId(Long houseId, Long bizId) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseByHouseIdAndBizId(houseId, bizId);
	}

	/**
	 * 查询业务房屋信息（缴存业务管理模块）
	 *
	 * @param houseCode 房屋编号
	 * @param bizId   业务ID
	 * @return 业务房屋信息（缴存业务管理模块）
	 */
	@Override
	public GwjDepositBusinessHouse selectGwjDepositBusinessHouseByHouseCodeAndBizId(String houseCode, Long bizId) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseByHouseCodeAndBizId(houseCode, bizId);
	}

	/**
	 * 查询业务房屋信息（缴存业务管理模块）列表
	 *
	 * @param gwjDepositBusinessHouse 业务房屋信息（缴存业务管理模块）
	 * @return 业务房屋信息（缴存业务管理模块）
	 */
	@Override
	public List<GwjDepositBusinessHouse> selectGwjDepositBusinessHouseList(GwjDepositBusinessHouse gwjDepositBusinessHouse) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseList(gwjDepositBusinessHouse);
	}

	/**
	 * 新增业务房屋信息（缴存业务管理模块）
	 *
	 * @param gwjDepositBusinessHouse 业务房屋信息（缴存业务管理模块）
	 * @return 结果
	 */
	@Override
	public int insertGwjDepositBusinessHouse(GwjDepositBusinessHouse gwjDepositBusinessHouse) {
		gwjDepositBusinessHouse.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		gwjDepositBusinessHouse.setCreateTime(DateUtils.getNowDate());
		return gwjDepositBusinessHouseMapper.insertGwjDepositBusinessHouse(gwjDepositBusinessHouse);
	}

	/**
	 * 修改业务房屋信息（缴存业务管理模块）
	 *
	 * @param gwjDepositBusinessHouse 业务房屋信息（缴存业务管理模块）
	 * @return 结果
	 */
	@Override
	public int updateGwjDepositBusinessHouse(GwjDepositBusinessHouse gwjDepositBusinessHouse) {
		gwjDepositBusinessHouse.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		gwjDepositBusinessHouse.setUpdateTime(DateUtils.getNowDate());
		return gwjDepositBusinessHouseMapper.updateGwjDepositBusinessHouse(gwjDepositBusinessHouse);
	}

	/**
	 * 批量删除业务房屋信息（缴存业务管理模块）
	 *
	 * @param bizHouseIds 需要删除的业务房屋信息（缴存业务管理模块）主键
	 * @return 结果
	 */
	@Override
	public int deleteGwjDepositBusinessHouseByBizHouseIds(Long[] bizHouseIds) {
		return gwjDepositBusinessHouseMapper.deleteGwjDepositBusinessHouseByBizHouseIds(bizHouseIds);
	}

	/**
	 * 删除业务房屋信息（缴存业务管理模块）
	 *
	 * @param bizId     业务ID
	 * @param buildCode 楼栋标识码
	 * @return 结果
	 */
	@Override
	public int deleteGwjDepositBusinessHouseByBizIdAndBuildCode(Long bizId, String buildCode) {
		return gwjDepositBusinessHouseMapper.deleteGwjDepositBusinessHouseByBizIdAndBuildCode(bizId, buildCode);
	}

	/**
	 * 删除业务房屋信息（缴存业务管理模块）信息
	 *
	 * @param bizHouseId 业务房屋信息（缴存业务管理模块）主键
	 * @return 结果
	 */
	@Override
	public int deleteGwjDepositBusinessHouseByBizHouseId(Long bizHouseId) {
		return gwjDepositBusinessHouseMapper.deleteGwjDepositBusinessHouseByBizHouseId(bizHouseId);
	}

	/**
	 * 根据业务ID查询业务房屋信息（缴存业务管理模块）列表
	 *
	 * @param bizId 业务ID
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjDepositBusinessHouse> selectGwjDepositBusinessHouseListByBizId(Long bizId) {
		GwjDepositBusinessHouse gwjDepositBusinessHouse = new GwjDepositBusinessHouse();
		gwjDepositBusinessHouse.setBizId(bizId);
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseList(gwjDepositBusinessHouse);
	}

	/**
	 * 根据业务ID和楼栋标识码查询业务房屋信息（缴存业务管理模块）列表
	 *
	 * @param bizId      业务ID
	 * @param buildCodes 楼栋标识码
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjDepositBusinessHouse> selectGwjDepositBusinessHouseListByBizIdAndBuildCodes(Long bizId, String[] buildCodes) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseListByBizIdAndBuildCode(bizId, buildCodes);
	}

	/**
	 * 根据业务ID和楼栋标识码查询业务房屋信息（缴存业务管理模块）列表
	 *
	 * @param bizId     业务ID
	 * @param buildCode 楼栋标识码
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjDepositBusinessHouse> selectGwjDepositBusinessHouseListByBizIdAndBuildCode(Long bizId, String buildCode) {
		GwjDepositBusinessHouse gwjDepositBusinessHouse = new GwjDepositBusinessHouse();
		gwjDepositBusinessHouse.setBizId(bizId);
		gwjDepositBusinessHouse.setBuildCode(buildCode);
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseList(gwjDepositBusinessHouse);
	}

	@Override
	public List<GwjRefundCompleteHouseDetailDTO> listBizHouseDTO(Long bizId, String buildCode) {
		return gwjDepositBusinessHouseMapper.listBizHouseDTO(bizId, buildCode);
	}

	/**
	 * 根据业务ID和楼栋标识码查询业务房屋信息（缴存业务管理模块）列表
	 *
	 * @param bizId      业务ID
	 * @param selectFlag 是否选中
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjDepositBusinessHouse> selectGwjDepositBusinessHouseListByBizIdAndSelectFlag(Long bizId, String selectFlag) {
		GwjDepositBusinessHouse gwjDepositBusinessHouse = new GwjDepositBusinessHouse();
		gwjDepositBusinessHouse.setBizId(bizId);
		gwjDepositBusinessHouse.setSelectFlag(selectFlag);
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseList(gwjDepositBusinessHouse);
	}

	/**
	 * 根据业务ID删除业务房屋信息（缴存业务管理模块）信息
	 *
	 * @param bizId 业务ID
	 * @return 结果
	 */
	@Override
	public int deleteGwjDepositBusinessHouseByBizId(Long bizId) {
		return gwjDepositBusinessHouseMapper.deleteGwjDepositBusinessHouseByBizId(bizId);
	}

	/**
	 * 查询业务房屋信息（缴存业务管理模块）列表  含楼栋信名称、业主名称
	 *
	 * @param gwjFundsSplitHouseRequest 业务房屋信息（缴存业务管理模块）
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjFundsSplitBusinessHouseDTO> selectGwjDepositBusinessHouseDetailList(GwjFundsSplitBusinessHouseRequest gwjFundsSplitHouseRequest) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseDetailList(gwjFundsSplitHouseRequest);
	}

	/**
	 * 查询业务房屋信息（缴存业务管理模块）列表  含业主名称
	 *
	 * @param gwjFundsSplitHouseRequest 业务房屋信息（缴存业务管理模块）
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjFundsSplitBusinessHouseDTO> selectGwjDepositBusinessHouseWithOwnerNameList(GwjFundsSplitBusinessHouseRequest gwjFundsSplitHouseRequest) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseWithOwnerNameList(gwjFundsSplitHouseRequest);
	}

	/**
	 * 查询业务房屋信息（缴存业务管理模块）列表  含楼栋信名称
	 *
	 * @param gwjFundsSplitHouseRequest 业务房屋信息（缴存业务管理模块）
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjFundsSplitBusinessHouseDTO> selectGwjDepositBusinessHouseWithBuildNameList(GwjFundsSplitBusinessHouseRequest gwjFundsSplitHouseRequest) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseWithBuildNameList(gwjFundsSplitHouseRequest);
	}

	/**
	 * 查询业务房屋信息（缴存业务管理模块）列表  含楼栋信名称、就算标准名称
	 *
	 * @param gwjFundsSplitHouseRequest 业务房屋信息（缴存业务管理模块）
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjFundsSplitBusinessHouseDTO> selectGwjDepositBusinessHouseWithBuildNameAndCalculateNameList(GwjFundsSplitBusinessHouseRequest gwjFundsSplitHouseRequest) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseWithBuildNameAndCalculateNameList(gwjFundsSplitHouseRequest);
	}

	/**
	 * 批量修改业务房屋信息（缴存业务管理模块）
	 *
	 * @param gwjDepositBusinessHouses 业务房屋信息（缴存业务管理模块）
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateBatchGwjDepositBusinessHouse(List<GwjDepositBusinessHouse> gwjDepositBusinessHouses) {
		gwjDepositBusinessHouses.forEach(h -> gwjDepositBusinessHouseMapper.updateGwjDepositBusinessHouse(h));
	}

	/**
	 * 根据业务ID和楼栋标识码统计预测面积
	 *
	 * @param bizId      业务ID
	 * @param buildCodes 楼栋标识码
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public BigDecimal countForecastSizeByBizIdAndBuildCodes(Long bizId, String[] buildCodes) {
		return gwjDepositBusinessHouseMapper.countForecastSizeByBizIdAndBuildCodes(bizId, buildCodes);
	}

	/**
	 * 根据业务ID和楼栋标识码统计实测面积
	 *
	 * @param bizId      业务ID
	 * @param buildCodes 楼栋标识码
	 * @return 业务房屋信息（缴存业务管理模块）集合
	 */
	@Override
	public BigDecimal countActualSizeByBizIdAndBuildCodes(Long bizId, String[] buildCodes) {
		return gwjDepositBusinessHouseMapper.countActualSizeByBizIdAndBuildCodes(bizId, buildCodes);
	}

	/**
	 * 批量信息房屋信息
	 *
	 * @param houseList 房屋信息
	 * @return
	 */
	@Override
	public Long insertGwjDepositBusinessHouses(List<GwjDepositBusinessHouse> houseList) {
		return gwjDepositBusinessHouseMapper.insertGwjDepositBusinessHouses(houseList);
	}

	/**
	 * 根据业务房屋主键查询业务参数
	 * @param bizHouseIds 业务房屋主键
	 * @return
	 */
	@Override
	public List<GwjDepositBusinessHouse> selectGwjDepositBusinessHouseListByBizIds(Long[] bizHouseIds) {
		return gwjDepositBusinessHouseMapper.selectGwjDepositBusinessHouseListByBizIds(bizHouseIds);
	}
}
